import { Example } from '~/server/models/example.model';
import { objectIdSchema } from '~/server/schemas/example.schema';
import { validateParam } from '~/server/utils/validation.server';

export default defineEventHandler(async (event) => {
  // 校验路由参数 ID
  const id = validateParam(event, objectIdSchema, 'id');

  // 查找数据
  const example = await Example.findById(id).lean();

  if (!example) {
    throw createError({
      statusCode: 404,
      statusMessage: '未找到指定的数据',
    });
  }

  return example;
});
